package com.tsxy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tsxy.entity.Menu;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 飞
 * @since 2022-02-17
 */
@Mapper
public interface MenuMapper extends BaseMapper<Menu> {

    @Select({"select * from sys_menu where pid is null"})
    @Results({
        @Result(column = "id",property = "id",jdbcType = JdbcType.INTEGER,id = true),
        @Result(column = "name",property = "name",jdbcType = JdbcType.VARCHAR),
        @Result(column = "path",property = "path",jdbcType = JdbcType.VARCHAR),
        @Result(column = "icon",property = "icon",jdbcType = JdbcType.VARCHAR),
        @Result(column = "description",property = "description",jdbcType = JdbcType.VARCHAR),
        @Result(column = "pid",property = "pid",jdbcType = JdbcType.INTEGER),
        @Result(column = "page_path",property = "pagePath",jdbcType = JdbcType.VARCHAR),
        @Result(column = "id",property = "children",
            many = @Many(select = "selectByPid"))
    })
    List<Menu> getAll();

    @Select({"select * from sys_menu where pid = #{pid}"})
    @Results({
            @Result(column = "id",property = "id",jdbcType = JdbcType.INTEGER,id = true),
            @Result(column = "name",property = "name",jdbcType = JdbcType.VARCHAR),
            @Result(column = "path",property = "path",jdbcType = JdbcType.VARCHAR),
            @Result(column = "icon",property = "icon",jdbcType = JdbcType.VARCHAR),
            @Result(column = "description",property = "description",jdbcType = JdbcType.VARCHAR),
            @Result(column = "pid",property = "pid",jdbcType = JdbcType.INTEGER),
            @Result(column = "page_path",property = "pagePath",jdbcType = JdbcType.VARCHAR),
            @Result(column = "id",property = "children",
                    many = @Many(select = "selectByPid"))
    })
    List<Menu> selectByPid(Integer pid);
}

